$(document).on('submit', '#newOrderForm',function (e) {
    e.preventDefault();
    $.ajax({
        type    :   'POST',
        url     :   'http://localhost:8080/mypetstore/newOrder',
        data    :   $('#newOrderForm').serialize(),
        success :   function (data){
            if (data.valid) {
                $("#Catalog").load("http://localhost:8080/mypetstore/confirmOrderForm #Catalog");
            }else {
                $('#creditCardTips').text("Invalid Card Number!").css("color","red").css("font-size", "15px");
            }
        },
        error   :   function (errorMsg){
            console.log(errorMsg);
        }
    })
});

$(document).on('submit', '#shippingForm',function (e) {
    e.preventDefault();
    $.ajax({
        type    :   'POST',
        url     :   'http://localhost:8080/mypetstore/shippingAddress',
        data    :   $('#shippingForm').serialize(),
        success :   function (){
                $("#Catalog").load("http://localhost:8080/mypetstore/confirmOrderForm #Catalog");
        },
        error   :   function (errorMsg){
            console.log(errorMsg);
        }
    })
});

$(document).on('click','#confirm', function () {
    $.ajax({
        type    : 'GET',
        url     : 'http://localhost:8080/mypetstore/viewOrder',
        success : function (data){
            if (data.valid) {
                $("#Catalog").load("http://localhost:8080/mypetstore/viewOrderForm #Catalog");
            }else {
                $("#Catalog").load("http://localhost:8080/mypetstore/errorForm #Catalog");
            }
        },
        error   : function (errorMsg){
            console.log(errorMsg);
        }
    });
});

$(document).on('click','#back', function () {
    $("#Catalog").load("http://localhost:8080/mypetstore/newOrderForm #Catalog");
});